package com.store.practice.controller;

import com.store.practice.common.api.CommonResult;
import com.store.practice.model.AppAccount;
import com.store.practice.service.SettingsManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "SettingsManageController",description = "设置")
@RequestMapping("/storeSettings")
@RestController
public class SettingsManageController {
    @Autowired
    private SettingsManageService settingsManageService;

    @ApiOperation("展示登录人员信息")
    @GetMapping("/getAccount")
    public CommonResult getAccount(Integer id){
        Map result = settingsManageService.getAccount(id);
        if (result==null){
            return CommonResult.failed();
        }
        return CommonResult.success(result);
    }

    @ApiOperation("修改密码")
    @PostMapping("/update")
    public CommonResult update(Integer id,String oldPw,String newPw){
        int i = settingsManageService.update(id, oldPw, newPw);
        if (i==-1){
            return CommonResult.failed("旧密码错误");
        }
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }
}
